/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the 
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef _MRP_MESSAGE_PROCESSING_THREAD_H_
#define _MRP_MESSAGE_PROCESSING_THREAD_H_

#define MRP_MESSAGE_ID_MIN									1 /* this macro's value needs to be set to the value of the first macro in the list */

#define MRP_MESSAGE_ID_PROCESS_INCOMING_MRPDU				1

#define MRP_MESSAGE_ID_LEAVE_ALL_TIMER_EXPIRE				2
#define MRP_MESSAGE_ID_PERIODIC_TRANSMISSION_TIMER_EXPIRE 	3
#define MRP_MESSAGE_ID_LEAVE_TIMER_EXPIRE					4

#define MRP_MESSAGE_ID_JOINTIMER_EXPIRE						5

#define MRP_MESSAGE_ID_PERIODIC_ENABLE						6
#define MRP_MESSAGE_ID_PERIODIC_DISABLE						7

#define MRP_MESSAGE_ID_LEAVE_ALL_BEGIN						8
#define MRP_MESSAGE_ID_PERIODIC_TRANSMISSION_BEGIN			9

#define MRP_MESSAGE_ID_MAD_JOIN_REQUEST						10
#define MRP_MESSAGE_ID_MAD_LEAVE_REQUEST					11

#define MRP_MESSAGE_ID_CALL_FUNCTION_ON_MESSAGE_THREAD		12

#define MRP_LEAVE_ALL_ATTRIBUTES							13

#define MRP_MESSAGE_ID_MAX									13 /* this macro's value needs to be set to the value of the last macro in the list */

struct mrp_message_processing_thread
{
    struct workqueue_struct * workqueue;
    struct work_struct work;
    
    spinlock_t message_list_lock;
    
    struct list_head message_list;
    
    int ref_count;
};

void mrp_message_processing_thread_init_lock(void);

struct mrp_message_processing_thread * mrp_message_processing_thread_get_instance(void);
void mrp_message_processing_thread_release_instance(void);

int mrp_message_processing_thread_submit_message(struct mrp_message_processing_thread * mrp_message_processing_thread, struct mrp * mrp, int message_id, void * data, void (*data_destroy_function)(void ** data));
int mrp_message_processing_thread_call_function(struct mrp_message_processing_thread * mrp_message_processing_thread, struct mrp * mrp, message_processing_thread_fucntion message_processing_thread_fucntion, void * data);

#endif
